#!/usr/bin/env python

import wx
import sys
import component

class Data(component.ListCtrl):
    '''Data class
    
    @author Julot <andy.julot@gmail.com>
    @since Monday, February 20, 2012. 03:20 PM'''
    
    def __init__(self, parent):
        style = wx.LC_REPORT | wx.LC_SINGLE_SEL
        component.ListCtrl.__init__(self, parent, style=style)
        self.InsertColumn(1, 'Time')
        self.InsertColumn(2, 'Latitude')
        self.InsertColumn(3, 'Longitude')
        self.InsertColumn(4, 'Depth')
        self.SetColumnWidth(3, wx.LIST_AUTOSIZE)
        self._textColour = self.GetTextColour()
    
    def add(self, data):
        label = data.dateTime.strftime('%Y-%m-%d %H:%M:%S')
        pos = self.InsertStringItem(sys.maxint, label=label)
        f = u'%s\u00B0 %s" %s'
        d = (data.latitude.degree, data.latitude.minute, data.latitude.mark)
        self.SetStringItem(pos, 1, f % d)
        d = (data.longitude.degree, data.longitude.minute, data.longitude.mark)
        self.SetStringItem(pos, 2, f % d)
        s = '%s %s' % (data.depth.value, data.depth.unit)
        self.SetStringItem(pos, 3, s)
        #self.SetItemState(pos, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
        self.EnsureVisible(pos)
        